"use strict";

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define(['elfinder'], factory);
    } else if (typeof exports !== 'undefined') {
        module.exports = factory(require('elfinder'));
    } else {
        factory(root.elFinder);
    }
}(this, function (elFinder) {
    elFinder.prototype.commands.mkofficefile = function () {
        var self = this,
            fm = self.fm,curOrg,
            setVar = function() {
                self.variants = [];
                self.variants.push([{command:"word"},'&nbsp; word文档']);
                self.variants.push([{command:"excel"},'&nbsp; excel文档']);
                self.variants.push([{command:"ppt"},'&nbsp; ppt文档']);
            };
        this.disableOnSearch = true;
        this.updateOnSelect = false;
        this.mime = 'text/plain';
        this.prefix = 'untitled file.txt';


    fm.bind('open', setVar)
        .bind('open', function () {
            fm.unbind('add', setVar).one('add', setVar);
        });

    this.getstate = function () {
        return this.fm.cwd().write ? 0 : -1;
    };

    this.exec = function (hashes, sortopt) {
        this.origin = curOrg ? curOrg : 'cwd';
        if (sortopt.command == "word") {
            this.mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
            this.prefix = 'untitled file.docx';
        } else if (sortopt.command == "excel") {
            this.mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
            this.prefix = 'untitled file.xlsx';
        } else if (sortopt.command == "ppt") {
            this.mime = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
            this.prefix = 'untitled file.pptx';
        }
        return $.proxy(fm.res('mixin', 'make'), self)();
    }

};

}))
;
